package com.supersit.greensproject.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.supersit.greensproject.R;

/**
 * 填写采集员个人信息
 * Created by 刘威 on 2015/11/4.
 */
public class FillUserInfoActivity extends BaseActivity {

    public static void startThis(Context context){
        Intent intent = new Intent(context,FillUserInfoActivity.class);
        context.startActivity(intent);
    }
//    姓名
    private EditText user_name;
//    单位名称
    private EditText unit_name;
//    电话
    private EditText user_phone;
//    地址
    private EditText user_address;
//    确定、取消按键
    private Button yes,no;

    private String user_name_str,unit_name_str,
            user_phone_str,user_address_str;


    public void setContentView() {
        setContentView(R.layout.activity_filluserinfo);
    }


    public void findViews() {
        user_name = (EditText) findViewById(R.id.user_name);
        unit_name = (EditText) findViewById(R.id.unit_name);
        user_phone = (EditText) findViewById(R.id.user_phone);
        user_address = (EditText) findViewById(R.id.user_address);
        yes = (Button) findViewById(R.id.userinfo_yes);
        no = (Button) findViewById(R.id.userinfo_no);
    }


    public void getData() {
        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(checkData()){
//                    填写数据发送，保存本地
                    SharedPreferences.Editor sp = FillUserInfoActivity.this
                            .getSharedPreferences("FILL_USER_INFO", Context.MODE_PRIVATE).edit();
                    sp.putString("user_name", user_name_str);
                    sp.putString("unit_name",unit_name_str);
                    sp.putString("user_phone",user_phone_str);
                    sp.putString("user_address", user_address_str);
                    sp.commit();
                }
            }
        });
        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    onDestroy();
            }
        });
    }


    public void showContent() {
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        user_name_str = savedInstanceState.getString("user_name");
        unit_name_str = savedInstanceState.getString("unit_name");
        user_phone_str = savedInstanceState.getString("user_phone");
        user_address_str = savedInstanceState.getString("user_address");
        user_name.setText(user_name_str);
        unit_name.setText(unit_name_str);
        user_phone.setText(user_phone_str);
        user_address.setText(user_address_str);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.clear();
        outState.putString("user_name", user_name_str);
        outState.putString("unit_name",unit_name_str);
        outState.putString("user_phone",user_phone_str);
        outState.putString("user_address",user_address_str);
        super.onSaveInstanceState(outState);
    }

    public void data(){
        user_name_str = user_name.getText().toString().trim();
        unit_name_str = unit_name.getText().toString().trim();
        user_phone_str = user_phone.getText().toString().trim();
        user_address_str = user_address.getText().toString().trim();
    }

    public boolean checkData(){
//        data();
//        if(TextUtils.isEmpty(user_name_str)){
//
//            toastManager.appToast("姓名不能为空",0);
//            return false;
//        }
//        if(TextUtils.isEmpty(unit_name_str)){
//            toastManager.appToast("单位名称不能为空",0);
//            return false;
//        }
//        if(TextUtils.isEmpty(user_phone_str)){
//            toastManager.appToast("电话不能为空",0);
//            return false;
//        }
//        if(TextUtils.isEmpty(user_address_str)){
//            toastManager.appToast("地址不能为空",0);
//            return false;
//        }
       return true;
    }
}
